package com.tanhua.api.impl.db;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.api.db.UserInfoApi;
import com.tanhua.domain.db.UserInfo;
import com.tanhua.mapper.db.UserInfoMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class UserInfoApiImpl implements UserInfoApi {

    @Autowired
    private UserInfoMapper userInfoMapper;

    @Override
    public void saveUserInfo(UserInfo userInfo) {
        userInfoMapper.insert(userInfo);
    }

    @Override
    public void update(UserInfo userInfo) {
        userInfoMapper.updateById(userInfo);
    }

    @Override
    public UserInfo findUserInfo(Long id) {
        return userInfoMapper.selectById(id);
    }

    @Override
    public IPage<UserInfo> findUsers(Integer page, Integer pagesize) {

        Page pg = new Page<>(page,pagesize);
        IPage<UserInfo> iPage = userInfoMapper.selectPage(pg, null);
        return iPage;
    }

    @Override
    public List<UserInfo> findAllUsers() {
        QueryWrapper<UserInfo> qr = new QueryWrapper<>();
        List<UserInfo> userInfoList = userInfoMapper.selectList(qr);
        return userInfoList;
    }

    @Override
    public UserInfo findById(int i) {
        UserInfo userInfo = userInfoMapper.selectById(i);
        return userInfo;
    }
}
